package project;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class TeamProject {

	Object temp;

	private Collection<?> ourList;

	public TeamProject(Collection<?> list) {
		this.ourList = list;
	}

	public String getListName() {

		String listName = ourList.getClass().toString();
		return listName;
	}

	private Object useless() {
		Iterator<?> itr = ourList.iterator();
		while (itr.hasNext()) {
			Object element = itr.next();
			if (temp != null && element.getClass() != temp.getClass()) {
				ourList.remove(element);
				return temp;
			}
			temp = element;
		}
		return null;
	}

	public void getMethod() {

		Set set = new HashSet();
		Object c1 = useless();

		Class<? extends Object> objectClass = c1.getClass();

		// Get the methods
		Method[] methods = objectClass.getDeclaredMethods();

		// Loop through the methods and print out their names
		for (Method method : methods) {
			set.add(method.getName());
		}
		
		for (Object method : set) {
			System.out.println(method);
		}

	}

	void serialization(Collection e) {

		try {
			FileOutputStream fileOut = new FileOutputStream("src/project/serialize.ser");
			ObjectOutputStream out = new ObjectOutputStream(fileOut);

			for (Object ob : e) {
				out.writeObject(ob);
			}

			out.close();
			fileOut.close();
			System.out.printf("\nSerialized data is saved in /src/project/serialize.ser");

		} catch (IOException i) {
			i.printStackTrace();
		}
	}
}